package cn.stylefeng.guns.modular.yingbao.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.yingbao.entity.UserMy;
import cn.stylefeng.guns.modular.yingbao.model.params.UserMyParam;
import cn.stylefeng.guns.modular.yingbao.service.UserMyService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import oracle.jdbc.proxy.annotation.Post;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 我的用户表控制器
 *
 * @author zs
 * @Date 2019-12-14 11:32:59
 */
@Api(tags = "我的用户模块")
@CrossOrigin
@Controller
@RequestMapping("/userMy")
public class UserMyController extends BaseController {

    private String PREFIX = "/userMy";

    @Autowired
    private UserMyService userMyService;

    /**
     * 跳转到主页面
     *
     * @author zs
     * @Date 2019-12-14
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/userMy.html";
    }

    /**
     * 新增页面
     *
     * @author zs
     * @Date 2019-12-14
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/userMy_add.html";
    }

    /**
     * 编辑页面
     *
     * @author zs
     * @Date 2019-12-14
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/userMy_edit.html";
    }

    /**
     * 新增接口
     *
     * @author zs
     * @Date 2019-12-14
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(UserMyParam userMyParam) {
        this.userMyService.add(userMyParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author zs
     * @Date 2019-12-14
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(UserMyParam userMyParam) {
        this.userMyService.update(userMyParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author zs
     * @Date 2019-12-14
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(UserMyParam userMyParam) {
        this.userMyService.delete(userMyParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author zs
     * @Date 2019-12-14
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(UserMyParam userMyParam) {
        UserMy detail = this.userMyService.getById(userMyParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author zs
     * @Date 2019-12-14
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(UserMyParam userMyParam) {
        return this.userMyService.findPageBySpec(userMyParam);
    }
    /******************************************************************************************************/


    @ApiOperation("添加用户资料")
    @PostMapping("addMyUser")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pic",value = "用户头像"),
            @ApiImplicitParam(name = "name",value = "用户名"),
            @ApiImplicitParam(name = "backup6",value = "用户id")
    })
    public ResponseData addMyUser(UserMy myUser){
        return this.userMyService.addMyUser(myUser);
    }

    @ApiOperation("查询某个用户")
    @PostMapping("queryById")
    @ResponseBody
    @ApiImplicitParam(name = "id",value = "用户主键id")
    public ResponseData queryById(Long id){
        return this.userMyService.queryById(id);
    }

    @ApiOperation("修改用户资料")
    @PostMapping("upByMyUser")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pic",value = "头像"),
            @ApiImplicitParam(name = "name",value = "用户名")
    })
    public ResponseData upByMyUser(String pic,String name,String id){
        return this.userMyService.upByMyUser(pic,name,id);
    }
}


